<template>

    <el-container id="loginbg">

        <el-header><h1>后台登录</h1></el-header>
        <el-main class="login-box">
            <el-form id="login" :model="numberValidateForm" ref="numberValidateForm" label-width="100px" class="demo-ruleForm">
                <el-form-item
                        label="账号"
                        prop="username"
                        :rules="[
                          { required: true, message: '账号不能为空'},
                        ]"
                >
                    <el-input type="age" v-model.number="numberValidateForm.username" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password"
                              :rules="[
                          { required: true, message: '密码不能为空'},
                        ]">
                    <el-input type="password" v-model="numberValidateForm.password"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button style="width:200px" type="primary" @click="submitForm('numberValidateForm')">提交</el-button>
                    <el-button style="width:180px" @click="resetForm('numberValidateForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </el-main>
    </el-container>
</template>

<style>

    .el-header{

        color: #333;
        text-align: center;
        line-height: 100px;
        margin-top: 50px;
    }

    h1{
        line-height: 60px;
    }

    .el-main {

        color: #333;
        text-align: center;

        margin-top: 100px;
    }

    .el-row {


    &
    :last-child {
        margin-bottom: 0;
    }

    }
    .login-box {

        text-align: center;
    }
    #login{
        width:500px;

        text-align: center;
        margin-left:30%;
    }
</style>

<script type="text/javascript">

    export default {

        data() {
            return {
                numberValidateForm: {
                    username: '',
                    password:'',
                }
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                       let formatDate = {
                            username:this.numberValidateForm.username,
                            password:this.numberValidateForm.password
                        }
                        axios.post('/admin/login',formatDate).then(rew=>{
                            if(rew.data==200){
                                this.open3();
                                location.href="/admin/index";
                            }
                             if(rew.data==400){
                                 this.open4();
                             }
                        })

                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            open3() {
                this.$notify({
                    title: '登录成功',
                    message: '点击关闭',
                    type: 'success'
                });
            },
            open4() {
                this.$notify({
                    title: '账号密码错误',
                    message: '点击关闭',
                    type: 'error'
                });
            },
        }
    }
</script>


